<template>
  <HomePanel title="新鲜好物" sub-title="新鲜出炉 品质靠谱" ref="target">
    <template #right>
      <!-- 封装好的悬浮样式结构和图标 -->
      <XtxMore></XtxMore>
    </template>
    <template #default>
      <ul ref="pannel" class="goods-list" v-if="list.length === 0">
        <li v-for="i in 4" :key="i">
          <XtxSkeleton :width="306" :height="306" />
        </li>
      </ul>
      <ul ref="pannel" class="goods-list" v-else>
        <li v-for="i in list" :key="i.id">
          <!-- 点击进行跳转 -->
          <RouterLink :to="`/product/${i.id}`">
          <!-- <RouterLink to="/"> -->
            <img :src="i.picture" alt="" />
            <p class="name">{{ i.name }}</p>
            <p class="price">&yen;{{ i.price }}</p>
          </RouterLink>
        </li>
      </ul>
    </template>
  </HomePanel>
</template>

<script>
import { reqFindNew } from '@/api/home'
import HomePanel from './home-panel'
// import { onMounted, ref } from 'vue-demi'
// import { useIntersectionObserver } from '@vueuse/core'
import { useObserver } from '@/compositions/index'
export default {
  components: { HomePanel },
  setup () {
    const { list, target } = useObserver(reqFindNew)
    return { list, target }
  }
}
</script>

<style scoped lang='less'>
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 406px;
  li {
    width: 306px;
    height: 406px;
    background: #f0f9f4;
    img {
      width: 306px;
      height: 306px;
    }
    p {
      font-size: 22px;
      padding-top: 12px;
      text-align: center;
      text-overflow: ellipsis;
      overflow: hidden;
      white-space: nowrap;
    }
    .price {
      color: @priceColor;
    }
  }
}
</style>
